#!/usr/bin/perl -w

use strict;
use warnings;
use utf8;
use open ':encoding(utf8)';
use lib '../';
use ImportHelpers;


my $sourceDir = ImportHelpers::getSourceDirName(__FILE__);
my $sourceURL = ImportHelpers::getSourceExternalURL($sourceDir);

my $whWorkID = ImportHelpers::insertWork(
	id        => 2,
	language  => 'grc',
	osis_id   => 'WH',
	name      => "Westcott/Hort",
	type      => 'manuscript-edition',
	copyright => "By <a href='http://en.wikipedia.org/wiki/Brooke_Foss_Westcott' title='Brooke Foss Westcott @ Wikipedia'>Brooke Foss Westcott</a> and <a href='http://en.wikipedia.org/wiki/Fenton_John_Anthony_Hort' title='Fenton John Anthony Hort @ Wikipedia'>Fenton John Anthony Hort</a>.",
	url       => $sourceURL,
	licenses  => [qw( http://creativecommons.org/licenses/publicdomain/ )]
);

#my $ubsWorkID = ImportHelpers::insertWork(
#	language  => 'grc',
#	osis_id   => 'NA27-UBS4',
#	name      => "Nestle-Aland 27th/UBS4",
#	type      => 'manuscript-edition',
#	copyright => "By <a href='http://en.wikipedia.org/wiki/Eberhard_Nestle' title='Eberhard Nestle @ Wikipedia'>Eberhard Nestle</a>, <a href='http://en.wikipedia.org/wiki/Erwin_Nestle' title='Erwin Nestle @ Wikipedia'>Erwin Nestle</a>, <a href='http://en.wikipedia.org/wiki/Kurt_Aland' title='Kurt Aland @ Wikipedia'>Kurt Aland</a>, <a href='http://www.biblesociety.org/'>United Bible Societies</a> et al",
#	url       => $sourceURL,
#	licenses  => []
#);


open IN, "$sourceDir/greek_WH_UBS4_parsed_utf8.txt"
	or die "Dir greek_WH_UBS4_parsed_utf8.txt doesn't exist.";

while(<IN>){
	#next if !/^62N\t/; #is 1 John
	next if not s/^(\d+\w)\t+(\d+)\t+(\d+)\t+\d+\t+//;
	
	my $book = $ImportHelpers::unboundNumToOsisCode{$1};
	next if !ImportHelpers::isBookOK($book);
	my $chapter = $2;
	my $verse = $3;
	
	s/\r//g;
	chomp;
	my @tokens;

	@tokens = ImportHelpers::parseUnboundVerseLine($_, 1);
	foreach my $token (@tokens){
		ImportHelpers::insertToken(
			work => $whWorkID,
			
			data => $token->{data},
			type => $token->{type},
			
			book => $book,
			chapter => $chapter,
			verse => $verse,
			
			parsing => $token->{parse},
			strongs => join(';', @{$token->{strongs}})
		);
	}
	
	#@tokens = ImportHelpers::parseUnboundVerseLine($_, 2);
	#foreach my $token (@tokens){
	#	ImportHelpers::insertToken(
	#		work => $ubsWorkID,
	#		
	#		data => $token->{data},
	#		type => $token->{type},
	#		
	#		book => $book,
	#		chapter => $chapter,
	#		verse => $verse,
	#		
	#		parsing => $token->{parse},
	#		strongs => join(';', @{$token->{strongs}})
	#	);
	#}
}
ImportHelpers::finishBookRefs($whWorkID);
#ImportHelpers::finishBookRefs($ubsWorkID);
close IN;

1;